<template>
	<!--
		
    	作者：offline
    	时间：2018-09-12
    	描述：会计对账单申请tabs页组件
	-->
	<div class="m-view-accountApplyComponents m-window" id="accApp" v-loading="loading">
		<el-form
			ref="headerRuleForm"
			label-width="60px"
			:inline-message="true"
			label-position="left"
			class="m-headerForm"
		>
			<el-row :gutter="10">
				<el-col :span="7">
					<el-form-item label="会计对账单号" class="rightItem" label-width="100px">
						<el-input v-model="accountCode" placeholder="会计对账单号" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="9" v-if="accountType==1&&pageLayOut=='add'">
					<el-form-item label="供应商" class="rightItem">
						<el-select
							filterable
							clearable
							v-model="supplierCode"
							placeholder="请选择供应商"
							@focus="focusMethod"
							@clear="supplierOptions=allSupplier"
							@change="supplierChange"
							:filter-method="filterSupplier"
						>
							<el-option
								v-for="item in supplierOptions"
								:key="item.id"
								:label="item.supplierName"
								:value="item.supplierCode"
							>
								<span style="float: left">{{ item.supplierName }}</span>
								<span style="float: right; color: #8492a6; font-size: 13px">{{ item.supplierCode }}</span>
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="8" v-else>
					<el-form-item label="供应商" class="rightItem">
						<el-input v-model="supplierName" placeholder="供应商" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="2" v-if="submitShow" class="m-floatright-col">
					<el-popover
						placement="top-start"
						title="提示"
						width="200"
						trigger="hover"
						content="【提交】:单据会提交到联塑公司"
					>
						<el-button type="primary" @click="submitAccountData" :disabled="btnDis" slot="reference">提交</el-button>
					</el-popover>
				</el-col>
				<el-col :span="2" v-if="saveBtnShow" class="m-floatright-col">
					<el-popover
						placement="top-start"
						title="提示"
						width="200"
						trigger="hover"
						content="【保存】:单据只会暂存在本地"
					>
						<el-button type="primary" @click="saveAccountData" :disabled="btnDis" slot="reference">保存</el-button>
					</el-popover>
				</el-col>
				<el-col :span="2" v-if="rollBtn" class="m-floatright-col">
					<el-button type="primary" @click="rollBackAccountData" :disabled="btnDis">退回</el-button>
				</el-col>
				<el-col :span="2" v-if="look_show" class="m-floatright-col">
					<el-button type="primary" @click="look">预览</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright-col">
					<el-button @click="cancel()" :disabled="btnDis" v-if="pageLayOut !=='add' ">返回</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright-col">
					<el-button @click="closePage" :disabled="btnDis" v-if="pageLayOut =='add' ">关闭</el-button>
				</el-col>

				<el-col :span="3" v-if="inconformity_check_show" class="m-floatright-col">
					<el-checkbox
						v-model="inconformity"
						@change="inconformity_change"
						:disabled="inconformity_inputDis"
					>不符模板</el-checkbox>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-col :span="7">
					<el-form-item
						:label="accountType==1?'公司':'客户'"
						class="rightItem"
						v-if="optionShow"
						label-width="100px"
					>
						<el-select
							value-key="id"
							v-model="selCompanyCode"
							:placeholder="`请选择${accountType==1?'公司':'客户'}`"
							@change="companyChange"
							ref="content"
							filterable
						>
							<el-option
								v-for="item in comOptions"
								:key="item.companyCode"
								:label="item.companyName"
								:value="item"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="客户" class="rightItem" v-if="labelShow" label-width="100px">
						<el-input v-model="customer" placeholder="客户" disabled></el-input>
					</el-form-item>
					<el-form-item label="公司" class="rightItem" v-if="companyLabelShow" label-width="100px">
						<el-input v-model="comName" placeholder="客户" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="17">
					<el-form-item label="备注" class="rightItem">
						<el-input
							placeholder="请输入备注(可编辑200字)"
							v-model="remark"
							maxlength="200"
							:disabled="remark_inputDis"
						></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-col :span="7">
					<el-form-item label="申请日期" class="rightItem" label-width="100px">
						<el-date-picker
							v-model="applyDate"
							type="date"
							placeholder="申请日期"
							value-format="yyyy-MM-dd HH:mm:ss"
							disabled
						></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="17">
					<el-form-item label="不符项" class="rightItem">
						<el-input
							placeholder="存在对账不符时可填写(可编辑100字)"
							v-model="unConMemo"
							maxlength="100"
							:disabled="unConMemo_inputDis"
						></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<!--实物对账单申请-->
		<div class="m-total">
			<div class="balance">
				<span>
					余额：
					<samp style="color:red" v-text="balance"></samp>元
				</span>
			</div>
			<div v-if="btnShow" class="m-floatright-col">
				<el-button @click="copyRow" :disabled="btnDis">复制行</el-button>
			</div>
			<div v-if="btnShow" class="m-floatright-col">
				<el-button @click="addNewRow" :disabled="btnDis">新增行</el-button>
			</div>
			<div v-if="btnShow" class="m-floatright-col">
				<el-button type="primary" @click="importPhysical" :disabled="btnDis">引入实物对账</el-button>
			</div>
		</div>
		<div class="m-mainContent m-top3">
			<el-tabs type="card">
				<el-tab-pane label="对账详情">
					<div class="m-agTable">
						<!--实物对账单-->
						<ag-grid-component
							ref="agGridComponent"
							:getColumnDefs="invoiceDetailsColumnDefs"
							:getRowSelection="'single'"
							:tableName="'accountApply'"
							:getGridOptions="invoiceDetailsGridOptions"
							:getRowData="invoiceDetailsRowData"
							:isColFit="true"
							:systemInfo="$systemInfo"
							v-loading="loading"
						></ag-grid-component>
					</div>
				</el-tab-pane>
				<el-tab-pane label="审批意见" v-if="pageLayOut!='add'&&signInfo.length>0">
					<sign-option-tab :signInfo="signInfo"></sign-option-tab>
				</el-tab-pane>
			</el-tabs>
		</div>

		<!--实物对账单列表-弹框-->
		<el-dialog
			custom-class="m-connetModel"
			title="选择实物对账单"
			:visible.sync="phyGoodsDialogVisible"
			width="80%"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
			:before-close="handleClose"
		>
			<el-row :gutter="10">
				<el-form label-width="70px" :inline-message="true" label-position="left" class="m-headerForm">
					<el-col :span="6">
						<!-- 客户：{{selCompanyName}} -->
						<el-form-item label="客户" class="rightItem">
							<el-input v-model="selCompanyName" placeholder disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="5">
						<el-form-item label="日期" class="rightItem">
							<el-date-picker
								v-model="applySDate"
								type="date"
								placeholder="单据申请开始日期"
								value-format="yyyy-MM-dd"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="4">
						<el-form-item class="rightItem" label-width="0">
							<el-date-picker
								v-model="applyEDate"
								type="date"
								placeholder="单据申请结束日期"
								value-format="yyyy-MM-dd"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="实物对账单号" class="rightItem" label-width="100px">
							<el-input v-model="phyCode" placeholder="输入实物对账单号" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="2">
						<el-button type="primary" @click="search">查询</el-button>
					</el-col>
				</el-form>
				<el-col :span="24">实物对账单列表：</el-col>
			</el-row>
			<div class="m-agTableModel">
				<ag-grid-vue
					class="m-agTableContent ag-theme-balham"
					:gridOptions="phyGoodsInfoOptions"
					:columnDefs="phyGoodsInfoColumnDefs"
					:rowData="phyGoodsInfoRowData"
					v-loading="diaLoading"
					rowSelection="multiple"
				></ag-grid-vue>
				<div class="m-page">
					<el-pagination
						@size-change="handleSizeChange"
						@current-change="handleCurrentChange"
						@prev-click="handlePrevClick"
						@next-click="handleNextClick"
						:current-page="currentPage"
						:page-sizes="[30,50,100,150,200]"
						:page-size="pageSize"
						layout="total, sizes, prev, pager, next, jumper"
						:total="total"
					></el-pagination>
				</div>
			</div>
			<el-row>
				<el-col :span="22">已选列表：</el-col>
				<el-col :span="2">
					<el-button @click="addStandByRows">添加</el-button>
				</el-col>
			</el-row>
			<div class="m-agTableModel">
				<ag-grid-vue
					class="m-agTableContent ag-theme-balham"
					:gridOptions="standbyInfoOptions"
					:columnDefs="standbyInfoColumnDefs"
					:rowData="standbyInfoRowData"
				></ag-grid-vue>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="cancelDialog">取消</el-button>
				<el-button type="primary" @click="saveStandbyData">保存</el-button>
			</span>
		</el-dialog>
		<!--签署文件预览-->
		<el-dialog
			:title="title"
			:visible.sync="dialogVisible"
			width="500px"
			top="50px"
			v-dialogDrag
			:before-close="handleClose2"
			:close-on-click-modal="false"
			:close-on-press-escape="false"
			class="m-reconciliationModel"
		>
			<el-row :gutter="10">
				<el-col :span="24" v-if="accord_show">
					<p>致{{sup_name}}：</p>
					<p
						style="text-indent:25px;"
					>我公司按照制度的要求，应当询证与贵公司的往来帐项等事项。下列信息出自我公司账簿记录，如与贵公司记录相符，请贵公司签署本函予以确认。若无特别注明，金额币种均为人民币，单位均为元。</p>
					<p>我公司与贵公司 {{sDate}} 至 {{eDate}} 往来账项列示如下：</p>
				</el-col>
				<el-col :span="24" v-if="inconformity_show">
					<p>致{{sup_name}}：</p>
					<p
						style="text-indent:25px;"
					>我公司按照制度的要求，应当询证与贵公司的往来帐项等事项。下列信息出自我公司账簿记录，如有不符，请贵公司签署本函，并与我公司相关工作人员确认不符项目或与我公司有关的未列入本函的其他项目。若无特别注明，金额币种均为人民币，单位均为元。</p>
					<p>我公司与贵公司 {{sDate}} 至 {{eDate}} 往来账项列示如下：</p>
				</el-col>
				<el-col :span="24">
					<el-table :data="tD_account" size="mini" border style="width: 100%; margin-bottom:20px;">
						<el-table-column prop="createDate" label="截止日期" width="90"></el-table-column>
						<el-table-column prop="initCharge" label="上期金额" width="100"></el-table-column>
						<el-table-column prop="handleCharge" label="本期应付金额" width="100"></el-table-column>
						<el-table-column prop="alreadyCharge" label="本期已付金额" width="100"></el-table-column>
						<el-table-column prop="reconcyAmount" label="期末余额" width="100"></el-table-column>
						<el-table-column prop="debt_type" label="欠款性质" width="70"></el-table-column>
						<el-table-column prop="contract_code" label="相应合同名称及编号" width="100"></el-table-column>
						<el-table-column prop="pay_date" label="支付日期" width="90"></el-table-column>
						<el-table-column prop="pay_type" label="支付方式" width="110"></el-table-column>
					</el-table>
				</el-col>
				<el-col
					:span="24"
					style="border-bottom:1px solid #ccc; margin-bottom:10px; padding-bottom:35px; text-align:right;"
				>
					<p>甲方：{{com_name}}</p>
					<p style="padding-right:145px;">盖章：</p>
				</el-col>
				<el-col :span="12" v-if="accord_show">
					<p style="padding-bottom: 40px;">信息证明无误。</p>
					<p>乙方：{{sup_name}}</p>
					<p>签章：</p>
				</el-col>
				<el-col :span="24" v-if="inconformity_show">
					<p>{{unConMemo}}</p>
					<p style="padding-bottom: 40px;">以上信息不符。</p>
					<p>乙方：{{sup_name}}</p>
					<p>签章：</p>
				</el-col>
			</el-row>
			<el-row :gutter="10" style="padding-bottom:15px;">
				<el-col :span="5" v-if="confirmBtn">
					<el-button type="primary" @click="confirmAccountData" :disabled="btnDis">确认</el-button>
				</el-col>
			</el-row>
		</el-dialog>
	</div>
</template>

<script>
import _Api from "@/api";
import localeText from "@/i18n/agGridText";
import Vue from "vue";
import waterfall from "async-es/waterfall";
import supplierInfo from "@/public/supplierInfo.js";
import serviceTime from "@/public/serverTime.js";
import DecimalEditorComponent from '@/components/DecimalEditorComponent.js';
import DatePickerComponent from '@/components/DatePickerComponent.js'
import SelectorComponents from '@/components/SelectorComponents.js'
import invoiceNoComponents from "@/components/invoiceNoComponents.js"
import subOperation from "@/public/subOperation.js"
import constant from "@/public/constant";
import Msg from "@/public/message.js";
import SignOptionTab from "./common/signOptionTab"
import gridOptions from 'lesso-common/public/gridOptions';

const operator = Vue.extend({
	template: `<span>
		<el-button type="text" @click="delDetails" class="rendererClass" size="mini" v-if=" delDetailsShow && params.node.data.id >=0 ? true :false ">删除</el-button>
		</span>`,
	data () {
		return {
			delDetailsShow: operator.delDetailsShow
		}
	},
	methods: {
		delDetails () {
			this.params.context.componentParent.deleteDetails(this.params.node.data);
		}
	}
})

export default {
	data () {
		return {
			accountCode: "",
			supplierName: "",
			supplierCode: "",
			optionShow: true,
			selCompanyCode: "",
			comOptions: [],
			labelShow: false,
			customer: "",
			companyLabelShow: false,
			comName: "",
			btnShow: true,
			remark: "",
			remark_inputDis: false,//备注的只读状态
			unConMemo_inputDis: false,//不符描述的只读状态
			invoiceDetailsColumnDefs: [],
			invoiceDetailsRowData: [],
			headerData: [],
			loading: false,
			storageDetailsColumnDefs: [],
			storageDetailsRowData: [],
			phyGoodsDialogVisible: false,
			selCompanyName: "",
			applyDate: "",
			phyGoodsInfoColumnDefs: [],
			phyGoodsInfoRowData: [],
			diaLoading: false,
			accountBtnShow: false,
			supplierBtnShow: true,
			btnDis: false,
			saveBtnShow: false,
			billTotalMoney: 0,
			invoiceTotalMoney: 0,
			balance: 0,
			applySDate: "",
			applyEDate: "",
			phyCode: "",
			standbyInfoColumnDefs: [],
			standbyInfoRowData: [],
			currentPage: 1,
			pageSize: 30,
			total: 0,
			physicalGoodSelRows: [],//实物对账选择数组
			invoiceSelRows: [],//发票选择数组
			submitShow: false,
			confirmBtn: false,
			rollBtn: false,
			colors: ['#FFFFFF', "#FF0000"],
			colorIndex: 1,
			dialogSize: document.body.clientWidth,
			unConMemo: "",//不符描述
			look_show: false,//浏览按钮
			dialogVisible: false,//签署文件预览
			title: "对账函",
			accord_show: true,//符合模板
			inconformity_show: true,//不符合模板
			sup_name: "",
			com_name: "",
			sDate: "",  //开始日期
			eDate: "",  //截止日期
			tD_account: [],
			inconformity_check_show: false,//不符模板勾选项的显示
			inconformity: false,//不符模板的勾选项
			look_flag: 0,//是否预览过 0-未预览 1-已预览
			inconformity_inputDis: false,
			//  审批意见相关
			signInfo: [],
			// 账户类型   
			accountType: this.$global.user.userTypeId,
			// 根据公司权限获取供应商数据
			supplierOptions: [],
			// 本地保存所有权限供应商
			allSupplier: [],
			// 当前供应商信息  
			supplierInfo: [],
			signMode: '',
			// 供应商对账余额信息
			sapBalance: {
				beginning: '', //期初
				handle: '', //应付
				paid: '' //已付
			}
		}
	},
	methods: {
		invoiceCellEditingStarted (params) {
			if (params.rowPinned)
				params.api.stopEditing();
		},
		//勾选不符模板
		inconformity_change () {
			// 勾选不符模板
			// if (this.inconformity == true)
			// {
			// 	不符描述为空时、只能退回
			// 	if (this.unConMemo == "")
			// 	{
			// 		this.confirmBtn = false;
			// 	}
			// 	else
			// 	{
			// 		this.confirmBtn = true;
			// 	}
			// }
		},
		//预览签署文件
		look () {
			//预览签署文件
			this.dialogVisible = true;
			//          	this.look_flag = 1;
		},
		handleClose2 (done) {
			done();
		},
		createData (count, prefix) {
			var result = [];
			for (let i = 0; i < count; i++) {
				result.push({
					gooAccNo: "合计",
					amount: this.billTotalMoney,
					invoiceMoney: this.invoiceTotalMoney
				})
			}
			return result;
		},
		getColor () {
			this.colorIndex = 1;
		},
		invoiceCellFocused (params) {
			var that = this;
			if (params.column) {
				this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
					let col = node.columnApi.getAllDisplayedColumns();
					if (that.pageLayOut == "edit" && that.setClickValue.billState > 1) {
						for (let c in col)
							col[c].editable = false;
					} else {
						for (let c in col) {
							if (col[c].colId == "busType") {
								col[c].colDef.editable = function (node) {
									if (node.data.gooAccNo == "")
										return true;
									else
										return false;
								}
							} else if (col[c].colId == "amount") {
								col[c].colDef.editable = function (node) {
									return false;
								}
							} else if (col[c].colId == "invoiceNo" || col[c].colId == "invoiceDate") {
								// col[c].colDef.editable = function (node) {
								//   if (node.data.gooAccNo == "")
								//     return false;
								//   else
								//     return true;
								// }
							}
						}
					}
				})
			}
		},
		cancel (signMode = '') {
			if (this.pageLayOut == "add") {
				let list = {
					cName: "会计对账列表",
					name: "accountBill",
					completed: true
				}
				this.removeTab()
				this.addTab(list)
				// console.log("关闭")
			} else {
				let obj = {
					signMode: signMode,
					isCancel: true
				}
				this.$emit("cancelComponents", obj);
			}
		},
		//保存会计对账单
		saveAccountData () {
			var that = this;
			this.$refs.agGridComponent.gridOptions.api.stopEditing();
			if (this.selCompanyCode == "") {

				Msg.showPopMsg("请选择客户!")
				return;
			}
			for (let j = this.invoiceSelRows.length - 1; j >= 0; j--) {
				if (this.invoiceSelRows[j].busType == "") {
					var row = [];
					row.push(this.invoiceSelRows[j]);
					this.$refs.agGridComponent.gridOptions.api.updateRowData({
						remove: row
					});
					this.invoiceSelRows.splice(j, 1);
				}
			}
			if (this.invoiceSelRows.length <= 0) {
				Msg.showPopMsg("请选择需要保存的数据!")
				return;
			}
			for (let i = 0; i < this.invoiceSelRows.length; i++) {
				if (this.invoiceSelRows[i].busType == 1) {
					if (!this.invoiceSelRows[i].invoiceNo || !this.invoiceSelRows[i].invoiceDate || !this.invoiceSelRows[i].invoiceMoney || !this.invoiceSelRows[i].busType) {
						// this.$alert("请完善实物对账单号为"+this.invoiceSelRows[i].gooAccNo + " 的相关信息(业务类型，发票号码、发票日期、发票金额)", {
						//     showClose: false,
						//     confirmButton: "确定",
						//     customClass: "alertPrompt"
						// });
						Msg.showPopMsg("请完善实物对账单号为" + this.invoiceSelRows[i].gooAccNo + " 的相关信息(业务类型、发票号码、发票日期、发票金额)")
						return;
					}
				}
				else if (this.invoiceSelRows[i].busType != "" && this.invoiceSelRows[i].busType != 1) {
					if (!this.invoiceSelRows[i].invoiceMoney || !this.invoiceSelRows[i].busType) {
						// this.$alert("请完善第 "+ (i+1) + " 行的信息(若选择非普通采购类型，请输入发票金额；若选择普通采购类型，请输入实物对账单号、对账金额、发票号码、发票日期以及发票金额)", {
						//     showClose: false,
						//     confirmButton: "确定",
						//     customClass: "alertPrompt"
						// });
						Msg.showPopMsg("请完善第 " + (i + 1) + " 行的信息(若选择非普通采购类型，请输入发票金额；若选择普通采购类型，请输入实物对账单号、对账金额、发票号码、发票日期以及发票金额)")
						return;
					}
				}
			}
			const { beginning, handle, paid } = this.sapBalance
			if (this.$global.user.userTypeId == "4") {
				if (this.pageLayOut == "add") {
					let obj = {};
					obj.accountNo = this.accountCode;//会计对账单号
					obj.id = 0;
					obj.companyCode = this.selCompanyCode.companyCode;//公司编码
					obj.companyId = this.selCompanyCode.id;//公司id
					if (this.$global.user.userTypeId == "4") {
						obj.creator = this.$global.user.employeeName;//创建人
						obj.creatorId = parseInt(this.$global.user.id);//创建人id
						obj.supplierCode = this.supplierInfo[0].supplierCode;//供应商编码
						obj.supplierId = this.supplierInfo[0].id;//供应商id
						obj.modifyer = this.$global.user.employeeName;//提交人
						obj.modifyerId = parseInt(this.$global.user.id);//提交人ID
					}
					obj.flag = 1;//提交或者保存标识1：保存，2：提交
					obj.remark = this.remark;//备注
					obj.unConMemo = this.unConMemo;//不符合描述
					//会计对账汇总
					for (let i = 0; i < this.invoiceSelRows.length; i++) {
						if (this.invoiceSelRows[i].invoiceDate)
							this.invoiceSelRows[i].invoiceDate = this.invoiceSelRows[i].invoiceDate + " 00:00:00";
					}
					obj.lAg = this.invoiceSelRows;
					obj.sapBalance = this.balance
					obj.signMode = this.signMode //已注册电子签标注为线上否则为线下签章
					obj.sapDebitSum = handle //应付
					obj.sapLendSum = paid //已付
					obj.sapOpenBalance = beginning //期初
					this.btnDis = true;

					_Api.postAccountBill(obj).then(function (response) {
						let data = response.data;
						if (data.code == "1") {
							Msg.showSuccessMsg("保存成功");
							that.cancel(obj.signMode);
						} else {
							Msg.showErrorMsg(data.info);
						}
						that.btnDis = false;
					}).catch((err) => {
						Msg.showErrorMsg(err.data.message);
						that.btnDis = false;
					})
				} else if (this.pageLayOut == "edit") {
					let obj = {};
					obj.accountNo = this.accountCode;
					obj.id = this.setClickValue.id;
					obj.companyCode = this.selCompanyCode.companyCode;
					obj.companyId = this.selCompanyCode.id;
					if (this.$global.user.userTypeId == "4") {
						obj.creator = this.$global.user.employeeName;//创建人
						obj.creatorId = parseInt(this.$global.user.id);//创建人id
						obj.supplierCode = this.supplierInfo[0].supplierCode;
						obj.supplierId = this.supplierInfo[0].id;
						obj.modifyer = this.$global.user.employeeName;//提交人
						obj.modifyerId = parseInt(this.$global.user.id);//提交人ID
					}
					obj.flag = 1;
					obj.remark = this.remark;
					obj.unConMemo = this.unConMemo;
					for (let a in this.invoiceSelRows) {
						if (this.invoiceSelRows[a].invoiceDate != "")
							this.invoiceSelRows[a].invoiceDate = new Date(this.invoiceSelRows[a].invoiceDate).Format("yyyy-MM-dd HH:mm:ss");
					}
					obj.lAg = this.invoiceSelRows;
					obj.sapBalance = this.balance;
					obj.signMode = this.setClickValue.signMode //已注册电子签标注为线上否则为线下签章
					obj.sapDebitSum = handle //应付
					obj.sapLendSum = paid //已付
					obj.sapOpenBalance = beginning //期初
					this.btnDis = true;
					_Api.postAccountBill(obj).then(function (response) {
						let data = response.data;
						if (data.code == "1") {
							Msg.showSuccessMsg("保存成功");
							that.cancel(obj.signMode);
						} else {
							Msg.showErrorMsg(data.info);
						}
						that.btnDis = false;
					}).catch((err) => {
						Msg.showErrorMsg(err.data.message);
						that.btnDis = false;
					})
				}
			}
		},
		submitAccountData () {
			//提交会计对账单
			var that = this;
			this.$refs.agGridComponent.gridOptions.api.stopEditing();
			if (this.selCompanyCode == "") {
				Msg.showPopMsg("请选择客户！")
				return;
			}
			for (let j = this.invoiceSelRows.length - 1; j >= 0; j--) {
				if (this.invoiceSelRows[j].busType == "") {
					var row = [];
					row.push(this.invoiceSelRows[j]);
					this.$refs.agGridComponent.gridOptions.api.updateRowData({
						remove: row
					});
					this.invoiceSelRows.splice(j, 1);
				}
			}
			if (this.invoiceSelRows.length <= 0) {
				Msg.showPopMsg("请选择需要保存的数据！")
				return;
			}
			for (let i = 0; i < this.invoiceSelRows.length; i++) {
				if (this.invoiceSelRows[i].busType == 1) {
					if (!this.invoiceSelRows[i].invoiceNo || !this.invoiceSelRows[i].invoiceDate || !this.invoiceSelRows[i].invoiceMoney || !this.invoiceSelRows[i].busType) {
						// this.$alert("请完善实物对账单号为："+this.invoiceSelRows[i].gooAccNo + " 的相关信息(业务类型,发票号码、发票日期、发票金额)", {
						//     showClose: false,
						//     confirmButton: "确定",
						//     customClass: "alertPrompt"
						// });
						Msg.showPopMsg("请完善实物对账单号为：" + this.invoiceSelRows[i].gooAccNo + " 的相关信息(业务类型,发票号码、发票日期、发票金额)")
						return;
					}
				} else if (this.invoiceSelRows[i].busType != "" && this.invoiceSelRows[i].busType != 1) {
					if (!this.invoiceSelRows[i].invoiceMoney || !this.invoiceSelRows[i].busType) {
						// this.$alert("请完善第 "+ (i+1) + " 行的信息(若选择非普通采购类型，请输入发票金额；若选择普通采购类型，请输入实物对账单号、对账金额、发票号码、发票日期以及发票金额)", {
						//     showClose: false,
						//     confirmButton: "确定",
						//     customClass: "alertPrompt"
						// });
						Msg.showPopMsg("请完善第 " + (i + 1) + " 行的信息(若选择非普通采购类型，请输入发票金额；若选择普通采购类型，请输入实物对账单号、对账金额、发票号码、发票日期以及发票金额)")
						return;
					}
				}
			}
			var copy = JSON.parse(JSON.stringify(this.invoiceSelRows));
			for (let k = copy.length - 1; k >= 0; k--) {
				if (copy[k].gooAccNo == "")
					copy.splice(k, 1);
			}
			for (let a = 0; a < copy.length; a++) {
				for (let b = 0; b < copy.length; b++) {
					if (a != b) {
						if (copy[a].gooAccNo == copy[b].gooAccNo) {
							copy[a].invoiceMoney = this.accAdd(copy[a].invoiceMoney, copy[b].invoiceMoney);
							copy.splice(b, 1);
							b = 0;
						}
					}
				}
			}
			for (let c in copy) {
				//                  if(parseFloat(copy[c].invoiceMoney) < parseFloat(copy[c].amount) || parseFloat(copy[c].invoiceMoney) > parseFloat(copy[c].amount))
				//                  {
				//                      this.$alert("实物对账单号："+copy[c].gooAccNo + " 发票总金额 与 对账金额不相符，请修改！", {
				//                          showClose: false,
				//                          confirmButton: "确定",
				//                          customClass: "alertPrompt"
				//                      });
				//                      return;
				//                  }
				var gap = subOperation.accSub(copy[c].invoiceMoney, copy[c].amount)
				if (parseFloat(gap) > 1 || parseFloat(gap) < -1) {
					// this.$alert("实物对账单号："+copy[c].gooAccNo + " 发票总金额 与 对账金额不相符，请修改！", {
					//     showClose: false,
					//     confirmButton: "确定",
					//     customClass: "alertPrompt"
					// });
					Msg.showPopMsg("实物对账单号：" + copy[c].gooAccNo + " 发票总金额 与 对账金额不相符，请修改！")
					return;
				}
			}
			const { beginning, handle, paid } = this.sapBalance
			if (this.pageLayOut == "add") {
				let obj = {};
				obj.accountNo = this.accountCode;//会计对账单号
				obj.id = 0;
				obj.companyCode = this.selCompanyCode.companyCode;//公司编码
				obj.companyId = this.selCompanyCode.id;//公司id
				if (this.$global.user.userTypeId == "4") {
					obj.creator = this.$global.user.employeeName;//创建人
					obj.creatorId = parseInt(this.$global.user.id);//创建人id
					obj.submitter = this.$global.user.employeeName;//提交人
					obj.summitterId = parseInt(this.$global.user.id);//提交人ID
					obj.supplierCode = this.supplierInfo[0].supplierCode;//供应商编码
					obj.supplierId = this.supplierInfo[0].id;//供应商id
					obj.modifyer = this.$global.user.employeeName;//提交人
					obj.modifyerId = parseInt(this.$global.user.id);//提交人ID
				}
				obj.flag = 2;//提交或者保存标识1：保存，2：提交
				obj.remark = this.remark;//备注
				obj.unConMemo = this.unConMemo;//不符合描述
				obj.sapBalance = this.balance;
				obj.sapDebitSum = handle //应付
				obj.sapLendSum = paid //已付
				obj.sapOpenBalance = beginning //期初
				//会计对账汇总
				for (let i = 0; i < this.invoiceSelRows.length; i++) {
					if (this.invoiceSelRows[i].invoiceDate != "" && this.invoiceSelRows[i].invoiceDate != null)
						this.invoiceSelRows[i].invoiceDate = this.invoiceSelRows[i].invoiceDate + " 00:00:00";
				}
				obj.lAg = this.invoiceSelRows;
				// obj.signMode = this.$global.supplierData.isESign == 2 ? 0 : 1//已注册电子签标注为线上否则为线下签章
				obj.signMode = this.signMode
				this.btnDis = true;

				_Api.postAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("保存成功")
						that.cancel(obj.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
					that.btnDis = false;
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
					that.btnDis = false;
				})
			} else {
				let obj = {};
				obj.accountNo = this.accountCode;
				obj.id = this.setClickValue.id;
				obj.companyCode = this.selCompanyCode.companyCode;
				obj.companyId = this.selCompanyCode.id;
				if (this.$global.user.userTypeId == "4") {
					obj.creator = this.$global.user.employeeName;//创建人
					obj.creatorId = parseInt(this.$global.user.id);//创建人id
					obj.submitter = this.$global.user.employeeName;//提交人
					obj.summitterId = parseInt(this.$global.user.id);//提交人ID
					obj.supplierCode = this.supplierInfo[0].supplierCode;
					obj.supplierId = this.supplierInfo[0].id;
					obj.modifyer = this.$global.user.employeeName;//提交人
					obj.modifyerId = parseInt(this.$global.user.id);//提交人ID
				}
				obj.flag = 2;
				obj.remark = this.remark;
				obj.unConMemo = this.unConMemo;
				obj.sapBalance = this.balance;
				obj.sapDebitSum = handle //应付
				obj.sapLendSum = paid //已付
				obj.sapOpenBalance = beginning //期初
				for (let a in this.invoiceSelRows) {
					if (this.invoiceSelRows[a].invoiceDate != "" && this.invoiceSelRows[a].invoiceDate != null)
						this.invoiceSelRows[a].invoiceDate = new Date(this.invoiceSelRows[a].invoiceDate).Format("yyyy-MM-dd HH:mm:ss");
				}
				obj.lAg = this.invoiceSelRows;
				// obj.signMode = this.$global.supplierData.isESign == 2 ? 0 : 1;//已注册电子签标注为线上否则为线下签章
				obj.signMode = this.setClickValue.signMode
				this.btnDis = true;
				_Api.postAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("保存成功")
						that.cancel(obj.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
					that.btnDis = false;
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
					that.btnDis = false;
				})
			}
		},
		importPhysical () {
			//引入实物对账单
			if (this.pageLayOut == "add") {
				if (!this.selCompanyCode.companyCode) {
					Msg.showPopMsg("请选择相关客户！")
					return;
				}
				if (this.accountType == 1 && !this.supplierCode) {
					Msg.showPopMsg("请选择供应商！")
					return;
				}
			}
			this.selCompanyName = this.selCompanyCode.companyName;
			this.phyGoodsDialogVisible = true;
			this.physicalGoodSelRows = [];
			var that = this;
			this.$refs.agGridComponent.gridOptions.api.stopEditing();
			for (let i = 0; i < this.invoiceSelRows.length; i++) {
				this.physicalGoodSelRows.push(this.invoiceSelRows[i]);
			}
			for (let i = 0; i < this.physicalGoodSelRows.length; i++) {
				for (let j = 0; j < this.physicalGoodSelRows.length; j++) {
					if (i != j) {
						if (this.physicalGoodSelRows[i].gooAccNo == this.physicalGoodSelRows[j].gooAccNo)
							this.physicalGoodSelRows.splice(j, 1);
					}
				}
			}
			setTimeout(() => {
				that.phyGoodsInfoOptions.api.hideOverlay();
				that.standbyInfoOptions.api.setRowData(that.physicalGoodSelRows);
				that.standbyInfoOptions.api.hideOverlay();
			}, 100);
		},
		// 选择客户或公司回调
		companyChange (params) {
			//切换公司
			if (this.invoiceSelRows.length > 0) {
				this.invoiceSelRows = [];
				this.physicalGoodSelRows = [];
				this.$refs.agGridComponent.gridOptions.api.setRowData([]);
				if (this.standbyInfoOptions.api)
					this.standbyInfoOptions.api.setRowData([]);
			}
			if (params != "") {
				if (this.accountType == 1 && this.pageLayOut == 'add') {
					this.getAuthSuppliers(params.companyCode)
				} else {
					let rowData = {
						supplierCode: this.supplierInfo[0].supplierCode,
						supplierId: this.supplierInfo[0].id,
						companyCode: params.companyCode,
						companyId: params.id
					}
					//   this.getSupplierBalance(this.supplierInfo[0].supplierCode, params.companyCode);
					this.getCompanySignmode(rowData)
				}
			}
			else {
				this.balance = 0;
			}
		},
		// 获取当前选择公司签署模式
		getCompanySignmode (rowData) {
			let params = {
				supplierId: rowData.supplierId,
				companyId: rowData.companyId
			}
			this.btnDis = true
			this.loading = true
			this.$http.getSupplierCompanyBySuppCompId(params).then(({ data }) => {
				// this.loading = false
				if (data.code == 1) {
					const { signMode } = data.rows
					this.signMode = signMode
					if (signMode == 0) {
						if (this.$global.supplierData.isESign != 2) {
							Msg.showPopMsg('当前供应商未开通电子签,暂不能进行后续操作!')
							this.loading = false
						} else {
							this.getSupplierBalance(rowData.supplierCode, rowData.companyCode)
						}
					} else {
						this.getSupplierBalance(rowData.supplierCode, rowData.companyCode)
					}
				} else {
					Msg.showErrorMsg(data.info)
					this.btnDis = false
					this.loading = false
				}
			}).catch(err => {
				this.btnDis = false
				Msg.showErrorMsg(err.data.message)
			})
		},
		getSupplierBalance (supplierCode, companyCode) {
			//获取余额
			var that = this;
			if (supplierCode && companyCode) {
				var obj = {
					supplierCode: supplierCode,
					companyCode: companyCode,
					reconcyDate: that.applyDate
				}
				// this.loading = true;
				// this.btnDis = true;
				_Api.getSupplierBalance(obj).then(function (response) {
					var data = response.data;
					that.loading = false;
					that.btnDis = false;
					if (data.code == "1") {
						const { beginning, handle, paid } = data.rows
						that.balance = data.rows.balance;
						that.sapBalance = {
							beginning: beginning || 0,
							handle: handle || 0,
							paid: paid || 0
						}
					} else {
						Msg.showErrorMsg(data.info);
						that.balance = 0;
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
					that.balance = 0;
					that.loading = false;
					that.btnDis = false;
				})
			}
		},
		handleClose (done) {
			this.applySDate = "";
			this.applyEDate = "";
			this.phyGoodsInfoOptions.api.setRowData([]);
			done();
		},
		search () {
			if (!this.phyCode) {
				if ((this.applySDate == null || this.applySDate == "") && (this.applyEDate == null || this.applyEDate == "")) {
					this.$alert("请选择日期段！", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					})
					return
				}
			}
			//          	if(this.applySDate > this.applyEDate){
			//          		this.$alert("提示：开始日期不能大于结束日期", {
			//						showClose: false,
			//						confirmButtonText: "确定",
			//						customClass: "alertPrompt"
			//					});
			//          		return;
			//          	};
			var obj = {};

			if (this.$global.user.userTypeId == "4")
				obj.userType = 2;
			else
				obj.userType = 1;
			obj.supplierId = this.supplierInfo[0].id;
			obj.companyId = this.selCompanyCode.id;
			if (this.phyCode != "")
				obj.gooAccMxMsgId = this.phyCode;
			obj.billState = 3;
			if (this.applySDate != "" && this.applySDate != null) {
				obj.begin_date = this.applySDate;
				if (this.applyEDate == "" || this.applyEDate == null)
					obj.end_date = obj.begin_date;
			}
			if (this.applyEDate != "" && this.applyEDate != null) {
				obj.end_date = this.applyEDate;
				if (this.applySDate == "" || this.applySDate == null)
					obj.begin_date = obj.end_date;
			}
			if (obj.begin_date != "" && obj.end_date != "") {
				if (obj.begin_date > obj.end_date) {
					this.$alert("提示：开始日期不能大于结束日期", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					})
					return
				}
			}
			//          	obj.begin_date = this.applySDate;
			//          	obj.end_date = this.applyEDate;
			obj.current = this.currentPage;
			obj.size = this.pageSize;
			obj.flag = 2;
			if (this.$global.user.userTypeId != "4")
				obj.accId = this.$global.user.id;
			var that = this;
			this.diaLoading = true;
			_Api.getMyGoodList(obj).then(function (response) {
				let data = response.data;
				if (data.code == "1") {
					if (data.total > 0) {
						that.phyGoodsInfoOptions.api.setRowData(data.rows.splice(0));
						that.phyGoodsInfoOptions.api.forEachNode(function (node) {
							node.data.id = 0;
						})
						that.total = data.total;
						for (let i = 0; i < that.physicalGoodSelRows.length; i++) {
							that.phyGoodsInfoOptions.api.forEachNode(function (node) {
								if (node.data.gooAccNo == that.physicalGoodSelRows[i].gooAccNo)
									node.setSelected(true);
							})
						}
					}
					else {
						that.phyGoodsInfoOptions.api.setRowData([]);
						that.total = 0;
					}
					that.diaLoading = false;
				} else {
					Msg.showErrorMsg(data.info);
					that.phyGoodsInfoOptions.api.setRowData([]);
					that.total = 0;
					that.diaLoading = false;
				}
			}).catch(() => {
				Msg.showErrorMsg("操作失败");
				that.diaLoading = false;
			})
		},
		saveData () {

		},
		getAccountNo () {
			var that = this;
			_Api.getAccountNo().then(function (response) {
				if (response.status == "200")
					that.accountCode = response.data;
				console.log(response.data)
			}).catch(() => {
				Msg.showErrorMsg("获取会计对账单号失败：请检查网络！");
			})
		},
		copyRow () {
			var row = JSON.parse(JSON.stringify(this.$refs.agGridComponent.gridOptions.api.getSelectedRows()));
			if (row.length == 1) {
				this.$refs.agGridComponent.gridOptions.api.stopEditing();
				row[0].invoiceDate = "";
				row[0].invoiceMoney = "";
				row[0].invoiceNo = "";
				row[0].id = 0;
				this.invoiceSelRows.push(row[0]);
				this.$refs.agGridComponent.gridOptions.api.updateRowData({
					add: [row[0]]
				})
				// this.$refs.agGridComponent.gridOptions.api.setRowData(this.invoiceSelRows);
				var cell = this.$refs.agGridComponent.gridOptions.api.getFocusedCell();
				if (cell) {
					this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
						if (node.rowIndex == cell.rowIndex)
							node.setSelected(true);
					})
				}
			} else {
				Msg.showPopMsg("请选择一行进行复制！")
				return;
			}
			//   this.$refs.agGridComponent.gridOptions.api.sizeColumnsToFit();
		},
		addNewRow () {
			var rowStr = "";
			this.$refs.agGridComponent.gridOptions.api.stopEditing();
			for (var i = 0; i < this.invoiceDetailsColumnDefs.length; i++) {
				if (this.invoiceDetailsColumnDefs[i].field != "")
					rowStr += '"' + this.invoiceDetailsColumnDefs[i].field + '":"",';
			}
			rowStr = rowStr.substring(0, rowStr.length - 1);
			var newRow = JSON.parse("{" + rowStr + "}");
			newRow.amount = 0;
			newRow.id = 0;
			newRow.busType = 1;
			this.invoiceSelRows.push(newRow);
			this.$refs.agGridComponent.gridOptions.api.updateRowData({
				add: [newRow]
			})
			// this.$refs.agGridComponent.gridOptions.api.setRowData(this.invoiceSelRows);
			//
			//   this.$refs.agGridComponent.gridOptions.api.sizeColumnsToFit();
		},
		addStandByRows () {
			var that = this;
			this.phyGoodsInfoOptions.api.forEachNode(function (node) {
				if (node.selected)
					that.physicalGoodSelRows.push(node.data);
				else {
					for (let i = that.physicalGoodSelRows.length - 1; i >= 0; i--) {
						if (that.physicalGoodSelRows[i].gooAccNo == node.data.gooAccNo)
							that.physicalGoodSelRows.splice(i, 1);
					}
				}
			});
			//去除重复行
			for (let i = 0; i < this.physicalGoodSelRows.length; i++) {
				for (let j = 0; j < this.physicalGoodSelRows.length; j++) {
					if (i != j) {
						if (this.physicalGoodSelRows[i].gooAccNo == this.physicalGoodSelRows[j].gooAccNo)
							this.physicalGoodSelRows.splice(j, 1);
					}
				}
			}
			this.standbyInfoOptions.api.setRowData(this.physicalGoodSelRows);
		},
		cancelDialog () {
			this.phyGoodsDialogVisible = false;
		},
		saveStandbyData () {
			var that = this;
			if (this.physicalGoodSelRows.length <= 0) {
				Msg.showPopMsg("请选择相关单据再保存！")
				return;
			}
			this.applySDate = "";
			this.applyEDate = "";
			this.phyCode = "";

			this.standbyInfoOptions.api.forEachNode(function (node) {
				let sum = 0;
				for (let i = 0; i < that.invoiceSelRows.length; i++) {
					if (node.data.gooAccNo == that.invoiceSelRows[i].gooAccNo)
						sum++;
				}
				if (sum == 0)
					that.invoiceSelRows.push(node.data);
			});
			this.standbyInfoOptions.api.setRowData([]);
			this.phyGoodsInfoOptions.api.setRowData([]);

			for (let k = 0; k < this.invoiceSelRows.length; k++) {
				this.invoiceSelRows[k].busType = 1;
			}
			this.$refs.agGridComponent.gridOptions.api.setRowData(this.invoiceSelRows);
			this.phyGoodsDialogVisible = false;

			this.invoiceTotalMoney = 0;
			this.billTotalMoney = 0;
			let count = 0;
			let list = [];
			this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
				count = 0;
				if (node.data.invoiceMoney) {
					that.invoiceTotalMoney = that.accAdd(node.data.invoiceMoney, that.invoiceTotalMoney);
					that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
				}
				for (let i = 0; i < list.length; i++) {
					if (list[i].gooAccNo == node.data.gooAccNo) {
						count++;
					}
				}
				if (count == 0) {
					list.push(node.data);
				}
			});
			for (let i = 0; i < list.length; i++) {
				this.billTotalMoney = this.accAdd(list[i].amount, this.billTotalMoney);
				this.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(this.createData(1, "Bottom"));
			}
			//   this.$refs.agGridComponent.gridOptions.api.sizeColumnsToFit();
		},
		handleSizeChange (params) {
			this.pageSize = params;
			this.search();
		},
		handleCurrentChange (params) {
			this.currentPage = params;
			this.search();
		},
		handlePrevClick (params) {
			this.currentPage = params;
			this.search();
		},
		handleNextClick (params) {
			this.currentPage = params;
			this.search();
		},
		deleteDetails (params) {
			if (params.id < 0) {
				return;
			}
			var that = this;
			if (params.id > 0) {
				let sumId = 0;
				this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
					if (node.data.id > 0)
						sumId++;
				})
				if (sumId == 1) {
					Msg.showPopMsg("至少保留1条已保存的数据！")
					return;
				}
			}
			this.$confirm("是否确认删除该数据？", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				distinguishCancelAndClose: true
			}).then(() => {
				if (params.id > 0) {
					var obj = {
						delFlag: 1,
						id: params.id,
						modifyer: this.$global.user.employeeName,
						modifyerId: this.$global.user.id
					};
					_Api.delAccountDetails(obj).then(function (response) {
						var data = response.data;
						if (data.code == "1") {
							that.afterDel(params);
						} else {
							Msg.showErrorMsg(data.info);
						}
					}).catch((err) => {
						Msg.showErrorMsg(err.data.message);
					})
				} else {
					that.afterDel(params);
				}
			}).catch(() => { })

			//          	var sum = 0;
			//          	var arr = [];
			//          	this.$refs.agGridComponent.gridOptions.api.forEachNode(function(node){
			//          		if(node.data.gooAccNo == params.gooAccNo)
			//          			sum++;
			//          	});
			//          	arr.push(params);
			//          	this.$refs.agGridComponent.gridOptions.api.updateRowData({
			//          		remove:arr
			//          	});
			//          	for(let i = this.invoiceSelRows.length - 1;i>=0;i--){
			//          		if(this.invoiceSelRows[i].gooAccNo == params.gooAccNo)
			//          			this.invoiceSelRows.splice(i,1);
			//          		break;
			//          	}
			//          	if(sum == 1)
			//          	{
			//          		for(let i = this.physicalGoodSelRows.length - 1;i >= 0 ;i--){
			//          			if(this.physicalGoodSelRows[i].gooAccNo == params.gooAccNo)
			//          				this.physicalGoodSelRows.splice(i,1);
			//          		}
			//          	}
			//          	this.invoiceTotalMoney = 0;
			//          	this.billTotalMoney = 0;
			//          	for (let a in this.invoiceSelRows) {
			//          		this.invoiceTotalMoney += this.accAdd(this.invoiceTotalMoney,this.invoiceSelRows[a].invoiceMoney);
			//          		this.billTotalMoney += this.accAdd(this.billTotalMoney,this.invoiceSelRows[a].amount);
			//          	}
		},
		afterDel (params) {
			var sum = 0;
			var arr = [];
			var that = this;
			this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
				if (node.data.gooAccNo == params.gooAccNo)
					sum++;
			});
			arr.push(params);
			this.$refs.agGridComponent.gridOptions.api.updateRowData({
				remove: arr
			});
			this.$refs.agGridComponent.gridOptions.api.hideOverlay();
			for (let i = this.invoiceSelRows.length - 1; i >= 0; i--) {
				if (this.invoiceSelRows[i].gooAccNo == params.gooAccNo) {
					this.invoiceSelRows.splice(i, 1);
					break;
				}
			}
			if (sum == 1) {
				for (let i = this.physicalGoodSelRows.length - 1; i >= 0; i--) {
					if (this.physicalGoodSelRows[i].gooAccNo == params.gooAccNo)
						this.physicalGoodSelRows.splice(i, 1);
				}
			}
			this.invoiceTotalMoney = 0;
			this.billTotalMoney = 0;
			let count = 0;
			let list = [];
			this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
				count = 0;
				if (node.data.invoiceMoney) {
					that.invoiceTotalMoney = that.accAdd(node.data.invoiceMoney, that.invoiceTotalMoney);
					// that.invoiceTotalMoney = that.invoiceTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
				}
				for (let i = 0; i < list.length; i++) {
					if (list[i].gooAccNo == node.data.gooAccNo) {
						count++;
					}
				}
				if (count == 0) {
					list.push(node.data);
				}
			});
			for (let i = 0; i < list.length; i++) {
				this.billTotalMoney = this.accAdd(list[i].amount, this.billTotalMoney);
			}
			// this.billTotalMoney = this.billTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		},
		accAdd (arg1, arg2) {
			var r1, r2, m, c;
			try {
				r1 = arg1.toString().split(".")[1].length;
			}
			catch (e) {
				r1 = 0;
			}
			try {
				r2 = arg2.toString().split(".")[1].length;
			}
			catch (e) {
				r2 = 0;
			}
			c = Math.abs(r1 - r2);
			m = Math.pow(10, Math.max(r1, r2));
			if (c > 0) {
				var cm = Math.pow(10, c);
				if (r1 > r2) {
					arg1 = Number(arg1.toString().replace(".", ""));
					arg2 = Number(arg2.toString().replace(".", "")) * cm;
				} else {
					arg1 = Number(arg1.toString().replace(".", "")) * cm;
					arg2 = Number(arg2.toString().replace(".", ""));
				}
			} else {
				arg1 = Number(arg1.toString().replace(".", ""));
				arg2 = Number(arg2.toString().replace(".", ""));
			}
			return (arg1 + arg2) / m;
		},
		invoiceCellValueChanged () {
			var that = this;
			this.invoiceTotalMoney = 0;
			this.billTotalMoney = 0;
			let count = 0;
			let list = [];
			this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
				count = 0;
				if (node.data.invoiceMoney) {
					that.invoiceTotalMoney = that.accAdd(node.data.invoiceMoney, that.invoiceTotalMoney);
					that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
				}
				for (let i = 0; i < list.length; i++) {
					if (list[i].gooAccNo == node.data.gooAccNo) {
						count++;
					}
				}
				if (count == 0) {
					list.push(node.data);
				}
			});
			for (let i = 0; i < list.length; i++) {
				this.billTotalMoney = this.accAdd(list[i].amount, this.billTotalMoney);
				this.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(this.createData(1, "Bottom"));
			}
			//this.billTotalMoney = this.billTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		},
		//确认会计对账单
		confirmAccountData () {
			var that = this;

			//判断当勾选了不符模板且不符描述为空时需要提示 jjc
			if (this.inconformity == true && this.unConMemo == "") {
				Msg.showPopMsg("选择不符模板时，请先将对账单【退回】给供应商填写不符项原因！")
				return;
			}

			//不符标记
			var unConFlag2;
			if (this.unConMemo != "")//不符描述 this.inconformity || 
				unConFlag2 = 1;
			else
				unConFlag2 = 0;

			this.$prompt("审批意见", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				customClass: 'promitBox',
				inputType: 'textarea',
				inputValue: '审核无误',
				distinguishCancelAndClose: true
			}).then(({ value }) => {
				var obj = {
					accountNo: that.setClickValue.accountNo,//会计对账单号
					id: that.setClickValue.id,//会计对账单id
					unConFlag: unConFlag2,//不符标记
					flag: 1,//确认
					callflag: 1,//应付人员页面标识
					confirmer: this.$global.user.employeeName,//确认人
					confirmerId: this.$global.user.id,//确认人ID
					supplierId: that.setClickValue.supplierId,
					companyId: that.setClickValue.companyId,
					signOption: value,
					modifyer: this.$global.user.employeeName,
					modifyerId: this.$global.user.id
				};
				_Api.putAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("操作成功！")
						that.cancel(that.setClickValue.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
				})
			}).catch(() => {
			})
		},
		//退回会计对账单
		rollBackAccountData () {
			var that = this;
			//不符标记
			var unConFlag2;
			if (this.inconformity)//不符模板的勾选
				unConFlag2 = 1;
			else
				unConFlag2 = 0;

			this.$prompt("审批意见", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				customClass: 'promitBox',
				inputType: 'textarea',
				inputValidator: (val) => {
					if (!val) {
						return '审批意见不能为空'
					}
				},
				distinguishCancelAndClose: true
			}).then(({ value }) => {
				var obj = {
					accountNo: that.setClickValue.accountNo,//会计对账单号
					id: that.setClickValue.id,//会计对账单ID
					unConFlag: unConFlag2,//不符标记
					flag: 2,//应付退回
					callflag: 1,//应付人员页面标识
					modifyer: this.$global.user.employeeName,//修改人名称
					modifyerId: this.$global.user.id,//修改人id
					supplierId: that.setClickValue.supplierId,
					companyId: that.setClickValue.companyId,
					summitterId: that.setClickValue.summitterId,
					signOption: value
				};
				_Api.putAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("操作成功")
						that.cancel(that.setClickValue.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
				})
			}).catch(() => {

			})
		},
		abandonAccountData () {
			var that = this;
			this.$confirm("是否弃审该数据？", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				distinguishCancelAndClose: true
			}).then(() => {
				var obj = {
					accountNo: that.setClickValue.accountNo,
					id: that.setClickValue.id,
					flag: 4,
					callflag: 1,
					modifyer: this.$global.user.employeeName,
					modifyerId: this.$global.user.id,
					supplierId: that.setClickValue.supplierId,
					companyId: that.setClickValue.companyId
				};
				_Api.putAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("操作成功")
						that.cancel(that.setClickValue.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
				})
			}).catch(() => {

			})
		},
		auditAccountData () {
			var that = this;
			this.$confirm("是否审核该数据？", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				distinguishCancelAndClose: true
			}).then(() => {
				var obj = {
					accountNo: that.setClickValue.accountNo,
					id: that.setClickValue.id,
					flag: 3,
					callflag: 1,
					auditor: this.$global.user.employeeName,
					auditorId: this.$global.user.id,
					supplierId: that.setClickValue.supplierId,
					companyId: that.setClickValue.companyId
				};
				_Api.putAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("操作成功")
						that.cancel();
					} else {
						Msg.showErrorMsg(data.info);
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
				})
			}).catch(() => {
			})
		},
		getBtnAuth () {
			var that = this;
			var obj = {
				resultType: "0",
				code: 'accountBill',
				authClientCode: constant.authCode.code,
				authTenantCode: constant.authCode.tcode
			};
			_Api.getUserAuthMenu(obj).then(function (response) {
				let data = response.data;
				let btnAuths = []
				if (data.code == "1") {
					if (data.total > 0) {
						for (let i in data.rows) {
							btnAuths.push(data.rows[i].code)
						}
						if (that.$global.user.userTypeId != "4") {
							if (that.pageLayOut == 'add') {
								that.confirmBtn = false;
								that.rollBtn = false;
								that.saveBtnShow = false;
								that.submitShow = false;
							} else {
								let billState = that.setClickValue.billState;
								// 判断按钮权限
								if (btnAuths.indexOf("confirmAccountData") > -1 && billState == 2)
									that.confirmBtn = true;
								else if (btnAuths.indexOf("confirmAccountData") > -1 && billState > 2)
									that.confirmBtn = false;
								if (btnAuths.indexOf("rollBackAccountData") > -1 && billState == 2)
									that.rollBtn = true;
								else if (btnAuths.indexOf("rollBackAccountData") > -1 && billState > 2)
									that.rollBtn = false;
							}
						} else if (that.$global.user.userTypeId == "4") {
							//   for (let i in data.rows) {
							if (that.pageLayOut == 'add') {
								if (btnAuths.indexOf("saveAccountData") > -1) {
									that.saveBtnShow = true;
								} else {
									that.saveBtnShow = false;
								}
								if (btnAuths.indexOf("submitAccountData") > -1) {
									that.submitShow = true;
								} else {
									that.submitShow = false;
								}
							} else if (that.pageLayOut == 'edit') {
								let billState = that.setClickValue.billState;
								if (btnAuths.indexOf("saveAccountData") > -1 && billState == 1)
									that.saveBtnShow = true;
								else
									that.saveBtnShow = false;
								if (btnAuths.indexOf("submitAccountData") > -1 && billState == 1)
									that.submitShow = true;
								else
									that.submitShow = false;
							}
							//   }
						}
					} else {
						that.confirmBtn = false;
						that.rollBtn = false;
						that.saveBtnShow = false;
						that.submitShow = false;
					}
				}
			})
		},
		getEditModeData () {
			//编辑状态下获取的数据信息
			var that = this;
			waterfall([
				function getSupplierBalance (callback) {
					var obj = {};
					that.loading = true;
					that.btnDis = true;
					if (that.setClickValue) {
						obj.supplierCode = that.setClickValue.supplierCode;
						obj.companyCode = that.setClickValue.companyCode;
						obj.reconcyDate = that.applyDate;
						_Api.getSupplierBalance(obj).then(function (response) {
							var data = response.data;
							if (data.code == "1") {
								that.balance = data.rows.balance || 0;
								const { beginning, handle, paid } = data.rows
								that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
								that.sup_name = that.setClickValue.supplierName;
								that.unConMemo = that.setClickValue.unConMemo;//不符描述
								that.com_name = that.setClickValue.companyName;
								that.sapBalance = {
									beginning: beginning || 0,
									handle: handle || 0,
									paid: paid || 0
								}
								var obj = [{
									createDate: data.rows.endDate,//截止日期-上个月最后一天
									initCharge: data.rows.beginning,//期初
									handleCharge: data.rows.handle,//应付
									alreadyCharge: data.rows.paid,//已付
									reconcyAmount: data.rows.balance,//余额
									debt_type: "应付账款",
									contract_code: that.setClickValue.contract_code,
									pay_date: "采购框架协议约定之日",
									pay_type: "汇票、电汇、信用证或其他"
								}];
								that.tD_account = obj;
								if (data.rows.endDate != null && data.rows.endDate != "") {
									that.sDate = (new Date(data.rows.endDate).getMonth() + 1) + "月01日";
									that.eDate = (new Date(data.rows.endDate).getMonth() + 1) + "月" + new Date(data.rows.endDate).getDate() + "日";
								}
								if (that.unConMemo == "") {
									that.accord_show = true;
									that.inconformity_show = false;
								}
								else {
									that.accord_show = false;
									that.inconformity_show = true;
								}
								callback(null, that.setClickValue);
							}
							else {
								that.$alert("获取余额失败！：" + data.info, {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertFailure"
								});
								Msg.showErrorMsg("获取余额失败！：" + data.info);
								that.balance = 0;
								that.loading = false;
								that.btnDis = false;
							}
						}).catch(() => {
							Msg.showErrorMsg("获取余额失败！");
							that.balance = 0;
							that.loading = false;
							that.btnDis = false;
						})
					}
				},
				function getAccountDetails (data, callback) {
					let obj = {
						accountNo: data.accountNo,
						id: data.id
					};
					_Api.getAccountDetails(obj).then(function (response) {
						let data = response.data;
						that.btnDis = false;
						that.loading = false;
						if (data.code == "1") {
							if (data.rows.mAccountTotal.length > 0) {
								that.invoiceSelRows = data.rows.mAccountTotal.splice(0);
								that.headerData = data.rows.tblAccountbill;
								//赋值备注和公司ID
								that.remark = that.headerData.remark;
								that.selCompanyCode.id = that.headerData.companyId;
								that.companyId = that.headerData.companyId;
								that.$refs.agGridComponent.gridOptions.api.setRowData(that.invoiceSelRows);//data.rows.mAccountDetail
								that.invoiceTotalMoney = 0;
								that.billTotalMoney = 0;
								let count = 0;
								let list = [];
								that.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
									count = 0;
									if (node.data.invoiceMoney) {
										that.invoiceTotalMoney = that.accAdd(node.data.invoiceMoney, that.invoiceTotalMoney);
										that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
									}
									for (let i = 0; i < list.length; i++) {
										if (list[i].gooAccNo == node.data.gooAccNo) {
											count++;
										}
									}
									if (count == 0) {
										list.push(node.data);
									}
								});
								for (let i = 0; i < list.length; i++) {
									that.billTotalMoney = that.accAdd(list[i].amount, that.billTotalMoney);
									that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
								}
								if (that.pageLayOut == "edit") {
									if (that.setClickValue.billState > 1) {
										let col = that.$refs.agGridComponent.gridOptions.columnApi.getAllDisplayedColumns();
										for (let c in col) {
											col[c].colDef.editable = false;
										}
									}
								}
								// that.$refs.agGridComponent.gridOptions.api.sizeColumnsToFit();
							}
						} else {
							Msg.showErrorMsg(data.info);
							that.btnDis = false;
						}
					}).catch(() => {
						Msg.showErrorMsg("操作失败");
						that.loading = false;
						that.btnDis = false;
					})
				}
			])
		},
		// 获取当前供应商所有的客户列表
		getAuthInfo () {
			let obj = {}
			if (constant.user.userTypeId == 4) {
				obj.account = constant.user.userName;
				obj.userType = 2;
				obj.flag = 1
			}
			else {
				obj.account = constant.user.oaNum;
				obj.userType = 1;
				obj.flag = 1
			}
			_Api.getAuthInfo(obj).then((res) => {
				let data = res.data
				if (data.code == 1) {
					this.comOptions = data.rows.myMstCompany
					if (this.comOptions.length > 0)
						// this.comOptions = this.authInfo;//绑定公司
						this.getAccountNo();//获取会计对账单号
					serviceTime.getServiceTime().then((serviceTime) => {
						this.applyDate = serviceTime.Format("yyyy-MM-dd");//绑定申请日期
					});
				} else {
					this.comOptions = []
				}
			})
				.catch(err => {
					Msg.showErrorMsg("操作失败");
					this.comOptions = []
				})
		},
		// 获取审批意见内容
		getAuditOptionData () {
			_Api.getSignOption({ billNo: this.accountCode }).then(({ data }) => {
				this.signLoading = false
				if (data.code == 1) {
					this.signInfo = data.rows
				} else {
					Msg.showErrorMsg(data.info)
				}
			}).catch(err => {
				Msg.showErrorMsg(err.data.message)
			})
		},
		// 获取当前公司所有供应商
		getAuthSuppliers (companyCode) {
			this.formLoading = true
			this.supplierCode = ''
			this.$http.getAuthSupplierByCompanyCode({ name: companyCode }).then(({ data }) => {
				this.formLoading = false
				if (data.code == 1) {
					this.supplierOptions = data.rows
					this.allSupplier = data.rows
				} else {
					Msg.showErrorMsg(data.info)
				}
			}).catch(err => {
				this.formLoading = false
				Msg.showErrorMsg(err.data.message)
			})
		},
		// 筛选供应商
		filterSupplier (value) {
			if (value != '') {
				this.supplierOptions = this.allSupplier.filter(item => item.supplierCode.indexOf(value) > -1 || item.supplierName.indexOf(value) > -1)
			} else {
				this.supplierOptions = this.allSupplier
			}
		},
		// 供应商下拉框获取焦点
		focusMethod () {
			if (!this.selCompanyCode) {
				Msg.showPopMsg('请先选择公司!')
				this.$refs.content.focus();
			}
		},
		// 供应商选择框下拉
		supplierChange (val) {
			for (let i = 0; i < this.supplierOptions.length; i++) {
				if (val == this.supplierOptions[i].supplierCode) {
					this.supplierInfo.push({
						supplierName: this.supplierOptions[i].supplierName,
						supplierCode: this.supplierOptions[i].supplierCode,
						id: this.supplierOptions[i].id
					})
					this.getSupplierBalance(this.supplierOptions[i].supplierCode, this.selCompanyCode.companyCode)
					return
				}
			}
		},
		// 关闭当前tab页
		closePage () {
			this.removeTab()
		}
	},
	watch: {
		dialogSize (val) {
			this.dialogSize = val;
			this.$nextTick(_ => {
				// that.$refs.agGridComponent.gridOptions.api.sizeColumnsToFit();
			})
		},
		billTotalMoney (val) {
			this.billTotalMoney = this.billTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		},
		invoiceTotalMoney (val) {
			//this.invoiceTotalMoney = this.invoiceTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		},
		balance (val) {
			//this.balance = this.balance.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		}
	},
	mounted () {
		var that = this;
		window.onresize = () => {
			return (() => {
				that.dialogSize = document.body.clientWidth;
			})();
		};
		this.getBtnAuth()
		if (this.$global.user.userTypeId == "4") {
			this.inconformity_check_show = false;
		}
		else {
			this.inconformity_check_show = true;
			this.unConMemo_inputDis = true;
		}
		//新增会计对账单
		if (this.pageLayOut == "add") {
			if (this.$global.user.userTypeId == "4") {
				supplierInfo.getUserInfo(this.$global.user.userName).then((supplierInfo) => {
					that.supplierInfo = supplierInfo;
					if (that.supplierInfo.length > 0)
						that.supplierName = that.supplierInfo[0].supplierName + " (" + that.supplierInfo[0].supplierCode + ")";
				});
			}
			this.getAuthInfo()
			this.inconformity_check_show = false;//不符模板的勾选项
			this.confirmBtn = false;//确认按钮
			this.rollBtn = false;//退回按钮
			this.look_show = false;//浏览按钮
			this.inconformity = false;//不符模板勾选
			this.remark_inputDis = false;//备注的可读状态
			this.unConMemo_inputDis = true;//不符模板的可读状态
			this.$set(operator, 'delDetailsShow', true);//
			this.$refs['agGridComponent'].gridOptions.api.setRowData([])
		}
		//浏览会计对账单
		else if (this.pageLayOut == "edit"||this.pageLayOut == "view") {
			const { supplierName, supplierCode, supplierId } = this.setClickValue
			this.optionShow = false;//选择实物对账单页面
			this.accountCode = this.setClickValue.accountNo;//会计对账单号
			this.applyDate = new Date(this.setClickValue.createDate).Format("yyyy-MM-dd");//申请日期
			this.getEditModeData();
			this.unConMemo = this.setClickValue.unConMemo;//不符描述
			//公司
			this.selCompanyCode = {};
			console.log('信息', this.setClickValue)
			this.selCompanyCode.companyName = this.setClickValue.companyName;
			this.selCompanyCode.companyCode = this.setClickValue.companyCode;
			this.supplierName = supplierName + " (" + supplierCode + ")";
			this.supplierInfo.push({
				supplierName,
				supplierCode,
				id: supplierId
			})
			//不符模板的勾选
			if (this.setClickValue.unConFlag == 0) {
				this.inconformity = false;
			} else if (this.setClickValue.unConFlag == 1) {
				this.inconformity = true;
				this.inconformity_inputDis = true;//不符的勾选
			}
			else//空值
				this.inconformity = false;
			//按钮控制-供应商
			if (this.$global.user.userTypeId == "4") {
				this.labelShow = true;//显示客户
				this.customer = this.setClickValue.companyName;//客户名称
				this.inconformity_check_show = false;//不符勾选项的显示            	
				//新增或退回
				if (this.setClickValue.billState == 1) {
					this.btnShow = true;//引入实物对账单的按钮
					// this.saveBtnShow = true;//保存按钮
					// this.submitShow = true;//提交按钮

					this.look_show = false;//浏览按钮
					this.confirmBtn = false;//确认按钮
					this.rollBtn = false;//退回按钮
					this.$set(operator, 'delDetailsShow', true);

					this.remark_inputDis = false;//备注的可读状态
					//判断是否勾选了不符模板
					//0-符合模板
					if (this.setClickValue.unConFlag == 0) {
						this.unConMemo_inputDis = true;//不符描述的可读状态
					}
					//1-不符合模板
					else {
						//判断单据状态是否为退回状态
						//1-退回状态
						if (this.setClickValue.retFlag == 1) {
							this.unConMemo_inputDis = false;//不符描述的可读状态
						}
						//0-
						else {
							this.unConMemo_inputDis = true;//不符描述的可读状态
						}
					}
				}
				//提交后
				else {
					this.btnShow = false;//引入实物对账单的按钮
					this.saveBtnShow = false;//保存按钮
					this.submitShow = false;//提交按钮

					this.look_show = false;//浏览按钮
					this.confirmBtn = false;//确认按钮
					this.rollBtn = false;//退回按钮

					this.remark_inputDis = true;//备注的可读状态
					this.unConMemo_inputDis = true;//不符描述的可读状态
					this.$set(operator, 'delDetailsShow', false);
				}
			}
			//按钮控制-公司
			else {
				this.companyLabelShow = true;//公司
				this.comName = this.setClickValue.companyName;//公司名称
				// this.supplierName = this.setClickValue.supplierName;//供应商名称
				this.remark_inputDis = true;//备注的可读状态
				this.unConMemo_inputDis = true;//不符描述的可读状态

				this.btnShow = false;//引入实物对账单的按钮
				this.saveBtnShow = false;//保存按钮
				this.submitShow = false;//提交按钮
				this.$set(operator, 'delDetailsShow', false);
				this.inconformity_check_show = true;//不符勾选项的显示    
				//提交状态
				if (this.setClickValue.billState == 2) {
					this.look_show = true;//浏览按钮
					//   this.confirmBtn = true;//确认按钮
					//   this.rollBtn = true;//退回按钮
				}
				//已确认状态和已审核状态
				else if (this.setClickValue.billState > 2) {
					this.look_show = true;//浏览按钮
					this.confirmBtn = false;//确认按钮
					this.rollBtn = false;//退回按钮
					this.inconformity_inputDis = true;//不符的勾选
				}
			}
			this.getAuditOptionData()
		}
	},
	components: {
		"sign-option-tab": SignOptionTab
	},
	props: {
		pageLayOut: {
			type: String,
			default: 'add'
		},
		authInfo: {
			type: Array
		},
		setClickValue: {
			type: Object
		},
		addTab: {
			type: Function
		},
		removeTab: {
			type: Function
		}
	},
	beforeMount () {
		var that = this;
		this.invoiceDetailsGridOptions = Object.assign({
			context: {
				componentParent: this
			},
			enableColResize: true,
			localeText: localeText,
			suppressRowClickSelection: true,
			onCellValueChanged: this.invoiceCellValueChanged,
			onCellFocused: this.invoiceCellFocused,
			onCellEditingStarted: this.invoiceCellEditingStarted,
			singleClickEdit: true,
			enableFilter: true, //列过滤器
			enableSorting: true, //列排序
			animateRows: true, //排序动画
			pinnedBottomRowData: this.createData(1, "Bottom"),
			getRowStyle: function (params) {
				if (params.data.invoiceMoney == '') {
					return { color: that.colors[that.colorIndex] };
				}
				if (params.node.rowPinned) {
					return { 'color': 'red', 'font-weight': 'bold' }
				}
			},
			isRowSelectable: function (rowNode) {
				if (that.pageLayOut == "edit") {
					if (that.setClickValue.billState > 1)
						return false;
					else if (that.setClickValue.billState === 1)
						return true;
				} else if (that.pageLayOut == "add") {
					return true;
				}
			}
		}, gridOptions({ dragSelectCheckbox: true, singleSelection: true, operation: true }))
		this.invoiceDetailsColumnDefs = [
			{				headerName: "业务类型", field: "busType", width: 130, editable: true, checkboxSelection: true, cellEditorFramework: SelectorComponents,
				cellRenderer: function (params) {
					if (params.value === 1)
						return '<span class="ag-icon">普通采购</span>';
					else if (params.value === 2)
						return '<span class="ag-icon">预付款</span>';
					else if (params.value === 3)
						return '<span class="ag-icon">期初</span>';
					else if (params.value === 4)
						return '<span class="ag-icon">调整</span>';
				}
				// pinned:'left'
			},
			{ headerName: "实物对账单号", field: "gooAccNo", width: 150 },
			{				headerName: "对账金额", field: "amount", width: 130, editable: false, cellRenderer: function (params) {
					if (params.value)
						return params.value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
					else
						return params.value;
				}//,cellEditorFramework:DecimalEditorComponent
			},
			{ headerName: "发票号码", field: "invoiceNo", width: 120, editable: true, cellEditorFramework: invoiceNoComponents },//NumericEditorComponent  
			{				headerName: "发票日期", field: "invoiceDate", width: 120, editable: true, cellEditorFramework: DatePickerComponent, cellRenderer: function (params) {
					if (params.value)
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
				}
			},
			{				headerName: "发票金额", field: "invoiceMoney", width: 130, editable: true, cellEditorFramework: DecimalEditorComponent, cellRenderer: function (params) {
					if (params.value)
						return params.value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
					else
						return params.value;
				}
			},
			{ headerName: "操作", field: "operator", width: 100, cellRendererFramework: operator, hide: false }
		];

		this.phyGoodsInfoOptions = {
			context: {
				componentParent: this
			},
			enableColResize: true,
			localeText: localeText,
			enableFilter: true, //列过滤器
			enableSorting: true, //列排序
			animateRows: true, //排序动画
			suppressRowClickSelection: true
		};
		this.phyGoodsInfoColumnDefs = [
			{ headerName: "实物对账单号", field: "gooAccNo", width: 200, checkboxSelection: true, headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true },
			{ headerName: "客户", field: "companyName", width: 200, tooltipField: 'companyName' },
			{ headerName: "对账金额", field: "amount", width: 130 },
			{				headerName: "申请日期", field: "createDate", width: 100, cellRenderer: function (params) {
					if (params.value && params.value != "")
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
				}
			},
			{ headerName: "确认人", field: "confirmer", width: 100 },
			{				headerName: "确认日期", field: "confirmDate", width: 100, cellRenderer: function (params) {
					if (params.value && params.value != "")
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
				}
			}
		];
		this.standbyInfoOptions = {
			context: {
				componentParent: this
			},
			enableColResize: true,
			localeText: localeText,
			enableFilter: true, //列过滤器
			enableSorting: true, //列排序
			animateRows: true, //排序动画
			suppressRowClickSelection: true
		};
		this.standbyInfoColumnDefs = [
			{				headerName: "序号", width: 100, cellRenderer: function (params) {
					return parseInt(params.node.id) + 1
				}
			},
			{ headerName: "实物对账单号", field: "gooAccNo", width: 150 },
			{ headerName: "客户", field: "companyName", width: 200, tooltipField: 'companyName' },
			{ headerName: "对账金额", field: "amount", width: 130 },
			{				headerName: "申请日期", field: "createDate", width: 100, cellRenderer: function (params) {
					if (params.value && params.value != "")
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format('yyyy-MM-dd')
				}
			},
			{ headerName: "确认人", field: "confirmer", width: 100 },
			{				headerName: "确认日期", field: "confirmDate", width: 100, cellRenderer: function (params) {
					if (params.value && params.value != "")
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format('yyyy-MM-dd');
				}
			}];
		if (this.pageLayOut == "edit") {
			if (this.setClickValue.billState > 1) {
				this.invoiceDetailsColumnDefs[this.invoiceDetailsColumnDefs.length - 1].hide = true;
			}
		}
	}
};
Date.prototype.Format = function (fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"H+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}
</script>